#ifndef SIMULATE_UART_H
#define SIMULATE_UART_H
#include "aky_define.h"

#define SIMULATE_UART_BUFF_MAX_SIZE 32
#define UART_RX_TIME_OUT_MAX 3


typedef enum e_cmd
{
    E_CMD_START_COMMAND = 0XF0, //开始指令
    E_CMD_300_PRES_FOR_CALIBRATION = 0XF1, //发送标准300点压力指令，用于校正
    E_CMD_300_PRES_FOR_COMPARING_LINEARITY = 0XF2, //发送300点压力指令，用于比对线性
    E_CMD_200_PRES_FOR_COMPARING_LINEARITY = 0XF3, //发送200点压力指令，用于比对线性
    E_CMD_100_PRES_FOR_COMPARING_LINEARITY = 0XF4, //发送100点压力指令，用于比对线性
    E_CMD_END_CMD = 0XF5, //发送结束指令

    E_CMD_IDLE,   //
} e_cmd_typedef;

typedef struct stru_cmd_decode
{
    e_cmd_typedef decode_cmd;
    e_cmd_typedef last_decode_cmd; //记住上一次的cmd值 用于校压力回复
    uint8 decode_buff[SIMULATE_UART_BUFF_MAX_SIZE];
    uint16 receive_cal_pres; //接收到的下发的校正值
    uint16 after_cal_pres; //校正后压力
    uint16 after_cal_pres_last; //上次校正后压力
    uint16 point_300_count;//300点count值
    uint16 point_zero_count;//0点count值
} stru_cmd_decode_typedef;

extern uint8 simulate_uart_buff[SIMULATE_UART_BUFF_MAX_SIZE];
extern uint16 simulate_uart_buff_receive_count;
extern stru_cmd_decode_typedef stru_cmd_decode;

void simulate_uart_init(void);
void simulate_uart_delay_us(unsigned int n);
unsigned char simulate_uart_read_byte(void);
void simulate_uart_send_byte(unsigned char dat);
void uart_get_buff_server(uint8_t dat);
uint8 uart_buff_decode_sever(stru_cmd_decode_typedef *p_stru_cmd_decode);
void cmd_decode_pro(stru_cmd_decode_typedef *p_stru_cmd_decode);
// void send_cmd(e_cmd_typedef cmd);
uint8 checke_cmd_ack(e_cmd_typedef cmd);
void send_ack_cmd(e_cmd_typedef cmd);
//放定时器中断处理
void uart_cmd_decode(void);
uint8 read_uart_rx_pin(void);
uint8_t uart_get_cmd_stat(void);

#endif
